package com.example.introductiontoprogramming;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class Programming2 extends AppCompatActivity {
    String a, b, c;


    private EditText edtTxtMaina;
    private EditText edtTxtMainb;
    private EditText edtTxtMainc;
    private Button btnMainJisuan;
    private TextView tvMainResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.programming_main2);
        initView();
    }

    private void initView() {
        edtTxtMaina = (EditText) findViewById(R.id.edtTxtMaina);
        edtTxtMainb = (EditText) findViewById(R.id.edtTxtMainb);
        edtTxtMainc = (EditText) findViewById(R.id.edtTxtMainc);
        btnMainJisuan = (Button) findViewById(R.id.btnMainJisuan);
        tvMainResult = (TextView) findViewById(R.id.tvMainResult);
    }

    public void resultonClick(View view) {
        //获取输入的内容并转换为字符串
        a = edtTxtMaina.getText().toString();
        b = edtTxtMainb.getText().toString();
        c = edtTxtMainc.getText().toString();

        //创建一个String类型数组
        String[] arr = {a, b, c};

        if (a.length() == 0 || b.length() == 0 || c.length() == 0) {
            Toast.makeText(Programming2.this, "请输入数字", Toast.LENGTH_SHORT).show();
        } else {
            //将String数组转换为int类型数组
            int[] arr2 = {Integer.parseInt(a), Integer.parseInt(b), Integer.parseInt(c)};

            int max = arr2[0];
            for (int i = 1; i < arr2.length; i++) {
                if (arr2[i] > max) {
                    max = arr2[i];
                    tvMainResult.setText(String.valueOf(arr2[i]));
                }

            }
        }

    }
}